var fs = require('fs');
var path = require('path');
/**
 * 判断指定路径下路径下文件是否存在
 * @param {文件路径} path 
 */
let isExists = (path) => {
  // console.log('path', path)
  var flag = fs.existsSync(path)
  return flag
}

let moveFileTo = (fileName, remotePath) => {
  return new Promise((resolve, reject) => {
    try {
      var sourceFile = path.join(__dirname, fileName);
      var readStream = fs.createReadStream(sourceFile);
      var writeStream = fs.createWriteStream(remotePath);
      readStream.pipe(writeStream)
      resolve(true)
    } catch (error) {
      reject(error)
    }
  })
}

let readFileContent = (filePath) => {
  return new Promise((resolve, reject) => {
    try {
      var data = fs.readFileSync(filePath, "utf-8")
      resolve(data)
    } catch (error) {
      reject(error)
    }
  })
}

module.exports = {
  isExists,
  moveFileTo,
  readFileContent
}